#include "camera.h"
#include "common.h"

Ray Camera::emitLight(double x, double y)
{
    double width = cameraForward.length();  // 屏幕宽度
    Vec cameraUp=( cameraForward.cross(cameraLeft) ).normalize(); //屏幕中心向上方的向量
    //屏幕上的坐标 原点在左上角 下方为x轴正方向 右方为y轴正方向

    Vec ll = cameraLeft * (1.0 - double(2 * y)/W) * width;
    Vec uu = cameraUp * (1.0 - double(2 * x)/H) * width;
    Vec direction = cameraForward + ll + uu;


    Vec tmp = cameraPosition + direction;
//    Vec newPos = cameraPosition + Vec(ran(), ran(), ran());
    Vec newPos = cameraPosition;
    return Ray(newPos, (tmp - newPos).normalize());
}



void Camera::setRGB(int x, int y, RGB color)
{
    ima[x][y].r = color.r * 255;
    ima[x][y].g = color.g * 255;
    ima[x][y].b = color.b * 255;
}
